//
//  WXLoginViewModel.swift
//  ExtremeHealth
//
//  Created by Zhongkai Li 李忠凯 on 2018/9/25.
//  Copyright © 2018 GanDongKeJi. All rights reserved.
//

import RxSwift
import Toast

struct WXLoginViewModel {
    func login(code: String,
               disposeBag: DisposeBag) {
        Network.request(target: .wxLogin(authCode: code),
                        success: { (obj: LoginModel) in
            let tokenInfo = TokenInfo(accessToken: obj.token, refreshToken: obj.token)
            AppUser.current.update(tokenInfo: tokenInfo)
            MainCoordinator.shared.home()
        }, failure: { (moyaError) in
            EHToast.show(moyaError.localizedDescription)
        }, error: { (error) in
            EHToast.show(error)
        }, dispose: disposeBag)
    }
}
